<#assign ctx=springMacroRequestContext.contextPath />
<#include "/macro/publicMacro.ftl">
<#import "/macro/pagination.ftl" as Pagination>
<#import "/macro/Dialog.ftl" as Dialog>

<@header title="登录用户表列表">
    <link href="${ctx}/resource/common/css/pagination.css" rel="stylesheet">
    <script src="${ctx}/resource/common/js/pagination.js"></script>
</@header>

<@body>
    <h2 class="module-title">登录用户表管理</h2>

    <div class="alert alert-primary" role="alert">
        <form class="form-inline">
            <div class="form-group mx-sm-3 mb-2">
                <label for="userName" >登录名称：</label>
                <input type="text" class="form-control" id="userName" name="userName" value="${user.userName}">
            </div>
            <div class="form-group mx-sm-3 mb-2">
                <label for="status" >用户状态：</label>
                <select class="form-control" name="status" id="status">
                    <option value="" >请选择</option>
                    <#list statusValues as status>
                        <option value="${status}" <#if status == user.status>selected</#if>>${status.desc}</option>
                    </#list>
                </select>
            </div>

            <div class="form-group mx-sm-3 mb-2">
                <button type="submit" class="btn btn-primary">查询</button>
            </div>

            <@shiro.hasPermission name="user:toAdd">
            <div class="form-group mx-sm-3 mb-2" style="float:right">
                <span style="float:left"><a href="${ctx}/user/toAdd">添加数据</a></span>
            </div>
            </@shiro.hasPermission>
        </form>
    </div>

    <div class="table-responsive">
        <table class="table table-striped table-bordered">
            <thead>
                <th>主键</th>
                <th>别称</th>
                <th>登录名称</th>
                <th>邮箱</th>
                <th>手机号</th>
                <th>用户状态</th>
<#--                <th width="180px">创建时间</th>-->
                <th width="180px">修改时间</th>
                <th>操作</th>
            </thead>
            <tbody>
            <#list users.beans as user>
                <tr>
                    <td>${user.id!}</td>
                    <td>${user.nickName!}</td>
                    <td>${user.userName!}</td>
                    <td>${user.maskEmail!}</td>
                    <td>${user.maskPhone!}</td>
                    <td>
                        <#if user.status == 'enable'><h5><span class="badge badge-success">${user.status.desc!}</span></h5></#if>
                        <#if user.status == 'disable'><h5><span class="badge badge-secondary">${user.status.desc!}</span></h5></#if>
                    </td>
<#--                    <th>${(user.createTime?string('yyyy-MM-dd hh:mm:ss'))!} </th>-->
                    <td>${(user.updateTime?string('yyyy-MM-dd hh:mm:ss'))!} </td>
                    <td><@shiro.hasPermission name="user_view"><a class="btn btn-primary btn-sm" href="${ctx}/user/view/${user.id?c}" role="button" aria-pressed="true">详情</a>
                        </@shiro.hasPermission>
                        <@shiro.hasPermission name="user:edit"><a class="btn btn-info btn-sm" href="${ctx}/user/toEdit/${user.id?c}" role="button" aria-pressed="true">编辑</a></@shiro.hasPermission>
                        <@shiro.hasPermission name="manager:userAuthorize"><a class="btn btn-warning btn-sm" href="${ctx}/manager/userAuthorize/${user.id?c}" role="button"
                                                                              aria-pressed="true">分配权限</a></@shiro.hasPermission>
                        <@shiro.hasPermission name="manager:userAuthorize_view"><a class="btn btn-info btn-sm" href="${ctx}/manager/userAuthorizeView/${user.id?c}" role="button"
                                                                                   aria-pressed="true">查看权限</a></@shiro.hasPermission>
                        <@shiro.hasPermission name="hasAumanager:changePassword"><button type="button" class="btn btn-light btn-sm" onclick="changePassword(${user.id?c})">重置密码</button></@shiro.hasPermission>
                        <@shiro.hasPermission name="user:clear_login')"><button type="button" class="btn btn-light btn-sm" onclick="clearLoginErrorNum(${user.id?c})">清除登录失败次数</button></@shiro.hasPermission>

                    </td>
                </tr>
            </#list>
            </tbody>
        </table>

        <@Pagination.pagination formId="userForm"
            pageNo=users.pageNo
            pageTotal=users.pageTotal
            total=users.total
            pageSize=users.pageSize
            action="${ctx}/user/list">
            <input type="hidden" name="userName" value="${user.userName}"/>
            <input type="hidden" name="status" value="${user.status}"/>
            <input type="hidden" name="module.id" value="${user.module.id}"/>
        </@Pagination.pagination>

        <@Dialog.Dialog id="changePasswordDialog" title="修改密码">
        </@Dialog.Dialog>
    </div>
</@body>

<@footer>
    <script>
        function changePassword(id) {
            $.ajax({
                url:"${ctx}/manager/changePassword/json/" + id, //请求的url地址
                dataType:"json", //返回格式为json
                async:true,//请求是否异步，默认为异步，这也是ajax重要特性
                type:"GET", //请求方式
                beforeSend:function(){
                    //请求前的处理
                },
                success:function(req){
                    $("#changePasswordDialog .modal-body").text("");
                    if (req.isSuccess) {
                        $("#changePasswordDialog .modal-body").text("新密码：" + req.newPassword);
                        $('#changePasswordDialog').modal({backdrop: 'static', keyboard: false})
                    } else {
                        $("#changePasswordDialog .modal-body").text("失败：" + req.msg);
                        $('#changePasswordDialog').modal({backdrop: 'static', keyboard: false})
                    }
                },
                complete:function(){
                    //请求完成的处理
                },
                error:function(){
                    $("#changePasswordDialog .modal-body").text("请求失败");
                    $('#changePasswordDialog').modal({backdrop: 'static', keyboard: false});
                }
            });
        }

        function clearLoginErrorNum(id) {
            $.ajax({
                url:"${ctx}/manager/clearLoginErrorNum/json/" + id, //请求的url地址
                dataType:"json", //返回格式为json
                async:true,//请求是否异步，默认为异步，这也是ajax重要特性
                type:"GET", //请求方式
                beforeSend:function(){
                    //请求前的处理
                },
                success:function(req){
                    $("#changePasswordDialog .modal-body").text("");
                    if (req.isSuccess) {
                        $("#changePasswordDialog .modal-body").text("成功清楚登录失败次数");
                        $('#changePasswordDialog').modal({backdrop: 'static', keyboard: false})
                    }
                },
                complete:function(){
                    //请求完成的处理
                },
                error:function(){
                    $("#changePasswordDialog .modal-body").text("请求失败");
                    $('#changePasswordDialog').modal({backdrop: 'static', keyboard: false});
                }
            });
        }
    </script>
</@footer>